function convert(input) { alert('Error. Contact us if this keeps happening.'); document.getElementById('modal-contact').classList.add('show'); } var _ctFfmpegMute = null; function _ctEnsureFfmpegMute() { if (_ctFfmpegMute) return Promise.resolve(_ctFfmpegMute); return loadScriptPromise('https://unpkg.com/@ffmpeg/ffmpeg@0.11.6/dist/ffmpeg.min.js').then(function() { var ns = window.FFmpeg || {}; if (!ns.createFFmpeg) throw new Error('FFmpeg library failed to load'); var ffmpeg = ns.createFFmpeg({ log: false, corePath: 'https://unpkg.com/@ffmpeg/core@0.11.0/dist/ffmpeg-core.js' }); _ctFfmpegMute = { ffmpeg: ffmpeg, fetchFile: ns.fetchFile }; return ffmpeg.load().then(function(){ return _ctFfmpegMute; }); }); } function processFile(blob, fileName) { var ext = ((fileName || '').toLowerCase().split('.').pop() || 'mp4'); var inName = 'in.' + ext; var outExt = (ext === 'webm' || ext === 'mkv') ? ext : 'mp4'; var outName = 'out.' + outExt; var outMime = outExt === 'webm' ? 'video/webm' : (outExt === 'mkv' ? 'video/x-matroska' : 'video/mp4'); _ctEnsureFfmpegMute().then(function(ctx) { var ffmpeg = ctx.ffmpeg, fetchFile = ctx.fetchFile; return fetchFile(blob).then(function(buf) { try { ffmpeg.FS('unlink', inName); } catch (e) {} try { ffmpeg.FS('unlink', outName); } catch (e) {} ffmpeg.FS('writeFile', inName, buf); function finish() { var data = ffmpeg.FS('readFile', outName); var outBlob = new Blob([data.buffer], { type: outMime }); var base = (fileName || 'video').replace(/\.[^.]+$/, ''); add_file_output(URL.createObjectURL(outBlob), base + '-muted.' + outExt); try { ffmpeg.FS('unlink', inName); } catch (e) {} try { ffmpeg.FS('unlink', outName); } catch (e) {} } var copyArgs = ['-i', inName, '-an', '-c:v', 'copy', '-movflags', 'faststart', outName]; return ffmpeg.run.apply(ffmpeg, copyArgs).then(finish).catch(function() { try { ffmpeg.FS('unlink', outName); } catch (e) {} var reArgs = ['-i', inName, '-an', '-c:v', 'libx264', '-preset', 'veryfast', '-pix_fmt', 'yuv420p', '-movflags', 'faststart', outName]; return ffmpeg.run.apply(ffmpeg, reArgs).then(finish); }); }); }).catch(function(err) { alert('Could not mute this video: ' + (err && err.message || err) + '. The first run downloads ~30 MB of conversion code - please check your connection and try again.'); }); } var _loadedScripts = {}; function loadScriptPromise(url) { if (_loadedScripts[url]) return _loadedScripts[url]; _loadedScripts[url] = new Promise(function (resolve, reject) { var s = document.createElement('script'); s.src = url; s.onload = resolve; s.onerror = reject; document.head.appendChild(s); }); return _loadedScripts[url]; } function replaceAll(find, replace, str) { return str.replace(new RegExp(find, 'g'), replace); } function beautify(str) { var result = ''; var length = str.length; var i = 0; var braceCountLeft = 0; var braceCountRight = 0; var withinQuotes = false; while (i < length) { var c = str[i]; if (c == '"' && (i == 0 || c[i - 1] != '\\')) { // non-escaped quotes withinQuotes = !withinQuotes; } if (!withinQuotes && (c == '}' || c == '{' || c == ',')) { console.log('Start####' + result); // look back and remove carriage returns and whitespace that are already there var resultIndex = result.length - 1; while (resultIndex >= 0 && (result[resultIndex] == ' ' || result[resultIndex] == '\r' || result[resultIndex] == '\n' || result[resultIndex] == '\t')) { resultIndex = resultIndex - 1; result = result.substr(0, resultIndex + 1); console.log('char ' + result[resultIndex] + '-----' + result + 'zzz ' + result.length + ' ' + resultIndex); } if (c == '{') { braceCountLeft++; result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } else if (c == '}') { braceCountRight++; // precede with carriage return result += '\r' + GetTabs(braceCountLeft - braceCountRight) + c; } else if (c == ',') { result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } var nextChar = ''; // advance through whitespace and remove carriage returns that are already there while (i < length && (str[i + 1] == ' ' || str[i + 1] == '\r' || str[i + 1] == '\n' || str[i + 1] == '\t')) { i++; } } else { result += str[i]; } i++; } return result; } function GetTabs(count) { var result = ''; for (var i = 0; i < count; i++) { result += ' '; } return result; }